<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="author" content="order by dede58.com"/>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>注册 - 简博客</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/login.css">
<link rel="apple-touch-icon-precomposed" href="images/icon/icon.jpg">
<link rel="shortcut icon" href="images/icon/icon.jpg">
<script src="js/jquery-2.1.4.min.js"></script>
<!--[if gte IE 9]>
  <script src="js/jquery-1.11.1.min.js" type="text/javascript"></script>
  <script src="js/html5shiv.min.js" type="text/javascript"></script>
  <script src="js/respond.min.js" type="text/javascript"></script>
  <script src="js/selectivizr-min.js" type="text/javascript"></script>
<![endif]-->
<!--[if lt IE 9]>
  <script>window.location.href='upgrade-browser.html';</script>
<![endif]-->

<!-- 更换验证码 -->
<!-- <script type="text/javascript">
    function refresh() {
        document.getElementById('captcha_img').src="http://location:8081/kaptcha?"+Math.random();
    }
</script> -->
</head>

<body class="user-select">
<div class="container">
  <div class="siteIcon"><img src="images/icon/icon.jpg" alt="" data-toggle="tooltip" data-placement="top" title="欢迎使用异清轩博客管理系统" draggable="false" /></div>
  <form id="form-signin" method="post" autocomplete="off" class="form-signin">
    <h2 class="form-signin-heading">用户注册</h2>
    <label for="username" class="sr-only">用户名</label>
    <input type="text" id="username" name="username" class="form-control" placeholder="请输入用户名" required autofocus autocomplete="off" maxlength="10">
    <label for="password" class="sr-only">密码</label>
    <input type="password" id="password" name="userpwd" class="form-control" placeholder="请输入密码" required autocomplete="off" maxlength="18">
    <label for="email" class="sr-only">邮箱</label>
    <input type="email" id="email" name="email" class="form-control" placeholder="请输入邮箱" required autofocus autocomplete="off" maxlength="25">
    
    <!-- <label for="verifyCodeActual" class="sr-only">验证码</label>
    <input type="text" id="verifyCodeActual" name="verifyCodeActual" class="form-control" placeholder="请输入验证码" required autofocus autocomplete="off" maxlength="25">
    <!-- 验证码图片 -->
    <!--<div class="item-input">
        <img id="captcha_img" title="点击更换" onclick="refresh()" src="http://localhost:8081/kaptcha" />
    </div> -->

    <button class="btn btn-lg btn-primary btn-block" type="button" id="signinSubmit">确定</button>
  </form>
  <div class="footer">
    <p><a href="http://localhost:63342/springboot-blogweb/login.html" data-toggle="tooltip" data-placement="left" title="有账号还注册？？？">登录 →</a></p>
  </div>
</div>
<script src="js/bootstrap.min.js"></script> 
<script>
$('[data-toggle="tooltip"]').tooltip();
window.oncontextmenu = function(){
	//return false;
};
$('.siteIcon img').click(function(){
	window.location.reload();
});


/**
 * 校验用户名是否存在
 */
$("#username").change(function(){
	if($('#username').val() === ''){
		$(this).text('用户名不能为空');
	}
	 $.ajax({
	        type:"get",
	        url:"http://localhost:8081/user/checkUsername",
	        xhrFields:{
	        	widthCredentials:true
	        },
	        async:false,
	        data:{
	        	"username":$("#username").val()
	        },
	        success:function (result) {
	            if (0==result.code){
	                alert("用户名已存在，请直接登录");
	                return false;
	            }
	        },
	       
	    })
});


/**
 * ajax异步提交注册
 */                     
$('#signinSubmit').click(function(){
	if($('#username').val() === ''){
		alert("用户名不能为空")
		return false;
	}else if($('#password').val() === ''){
		alert('密码不能为空')
		return false;
	}else if($('#email').val() === ''){
		alert('邮箱不能为空')
		return false;
	}/*else if($("#verifyCodeActual").val() === ''){
		$(this).text('验证码不能为空');
	}*/
 $.ajax({
        type:"post",
        url:"http://localhost:8081/user/insertUser",
        xhrFields:{
        	widthCredentials:true
        },
        async:false,
        data:{
        	"username":$("#username").val(),
        	"password":$("#password").val(),
        	"email":$("#email").val()
        	/*"verifyCodeActual":$("#verifyCodeActual").val()*/
        },
        success:function (result) {
            if (0==result.code){
                alert("注册成功");
                window.location.href ="login.html";
               
            }else {
                alert("注册失败，请重新注册");
            }
        },
        error:function (result) {
            alert("未知错误");
        }
    })

});
</script>
</body>
</html>
